#ifndef SunIAC_First
#define SunIAC_First
#ifdef __GNUG__
#pragma interface
#endif

#include "IAC.h"

class SunIAC;
class SunIACHandler;
class SeqCollection;

#define SERVERNAME "ET++clipboard"
#define SERVICENAME "et++clipboard"

//---- block -------------------------------------------------------------------

class block {
public:
	int len, pos;
	char *buf;

public:
	block();
	~block();
};

//---- SunMsg ------------------------------------------------------------------

class SunMsg : public Object {
public:
	SunMsg();
	SunMsg(int to, int from, int reply, const char *buf, int l= -1, bool makecopy= TRUE);

	int From();
	int To();
	int Serial();
	char *Data();
	int Len();

	void SetFrom(int fr);
	void Prepare();
	int Read(int fd);
	int Write(int fd);
	void Print(char *from);

private:
	int from, to, serial;
	struct block data[2];
};

inline int SunMsg::From()
	{ return from; }
inline int SunMsg::To()
	{ return to; }
inline int SunMsg::Serial()
	{ return serial; }
inline char *SunMsg::Data()
	{ return data[1].buf; }
inline int SunMsg::Len()
	{ return data[1].len; }

//---- SunIAC ------------------------------------------------------------------

class SunIAC : public IACImpl {
public:
	SunIAC(IAC *sc);
	SunIAC(int fd);
	~SunIAC();
	void Init(int fd);
	int Open(const char *nm);
	int Close(const char *nm);
	int LookupName(const char *nm, bool start);
	int SendTo(int to, int ser, const char *buf= 0, int len= -1);
	int Broadcast(int ser, const char *buf, int len= -1);
	int Poll(int ser, const char *buf, int len= -1);
	int SendReply(int to, int ser, int code, const char *buf= 0, int len= -1);
	bool ReadNotify();
	bool WriteNotify();
	bool HasWriteInterest();

	virtual void Dispatch(SunMsg *m);
	int SendMessage(SunMsg *m);

protected:
	int sid;
	SunIACHandler *handler;
	SeqCollection *wqueue;
	SunMsg *rm;
};

#endif

